package com.openspring.framework.extend.shiro;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.PathMatchingFilter;

/**
 * 用于登录后换用户名登录
 * 配置在FormAuthenticationFilter前面
 * @author hebin
 *
 */
public class BeforeLoginFilter extends PathMatchingFilter {

	@Override
	protected boolean preHandle(ServletRequest request, ServletResponse response)
			throws Exception {
		Subject subject = SecurityUtils.getSubject();
		if(subject.isAuthenticated())
			subject.logout();
		return super.preHandle(request, response);
	}

}
